namespace SmartSoft.Invoices
{
    using SmartSoft;
    using SmartSoft.Controls;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormResetInvoiceOrder : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private IContainer components;
        private bool ib_CheckAccepted;
        private LabelControl labelControl2;
        private LabelControl lblFormat;
        private LabelControl lblNgay_Ct1;
        private LabelControl lblNgay_Ct2;
        private LabelControl lblStart;
        public TextControl txtFormat;
        private TextDate txtNgay_Ct1;
        private TextDate txtNgay_Ct2;
        private TextNumeric txtStart;

        public FormResetInvoiceOrder()
        {
            this.InitializeComponent();
            this.txtNgay_Ct1.Value = AppInstance.StartWorkingDate;
            this.txtNgay_Ct2.Value = AppInstance.EndWorkingDate;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.OnOk())
            {
                base.Close();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormResetInvoiceOrder));
            this.btnCancel = new BtnControl();
            this.btnOk = new BtnControl();
            this.txtNgay_Ct2 = new TextDate();
            this.lblNgay_Ct2 = new LabelControl();
            this.txtNgay_Ct1 = new TextDate();
            this.lblNgay_Ct1 = new LabelControl();
            this.lblFormat = new LabelControl();
            this.txtFormat = new TextControl();
            this.txtStart = new TextNumeric();
            this.lblStart = new LabelControl();
            this.labelControl2 = new LabelControl();
            base.SuspendLayout();
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            //this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Font = new Font("Arial", 8.25f);
            this.btnCancel.Location = new Point(310, 0x90);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x76, 0x17);
            this.btnCancel.TabIndex = 5;
            this.btnCancel.Text = "&Hủy bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnOk.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnOk.Font = new Font("Arial", 8.25f);
            this.btnOk.Location = new Point(12, 0x90);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new Size(0x76, 0x17);
            this.btnOk.TabIndex = 4;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new EventHandler(this.btnOk_Click);
            this.txtNgay_Ct2.DateTimeFormat = TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct2.Font = new Font("Arial", 8.25f);
            this.txtNgay_Ct2.InsertKeyMode = InsertKeyMode.Overwrite;
            this.txtNgay_Ct2.Location = new Point(0x83, 0x26);
            this.txtNgay_Ct2.Mask = "00/00/0000";
            this.txtNgay_Ct2.Name = "txtNgay_Ct2";
            this.txtNgay_Ct2.OldValue = null;
            this.txtNgay_Ct2.Size = new Size(100, 20);
            this.txtNgay_Ct2.TabIndex = 1;
//            this.txtNgay_Ct2.Value = null;//manager.GetObject("txtNgay_Ct2.Value");
            this.lblNgay_Ct2.AutoSize = true;
            this.lblNgay_Ct2.Font = new Font("Arial", 8.25f);
            this.lblNgay_Ct2.Location = new Point(0x23, 0x29);
            this.lblNgay_Ct2.Name = "lblNgay_Ct2";
            this.lblNgay_Ct2.Size = new Size(0x36, 14);
            this.lblNgay_Ct2.TabIndex = 0x65;
            this.lblNgay_Ct2.Text = "Đến ngày";
            this.txtNgay_Ct1.DateTimeFormat = TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct1.Font = new Font("Arial", 8.25f);
            this.txtNgay_Ct1.InsertKeyMode = InsertKeyMode.Overwrite;
            this.txtNgay_Ct1.Location = new Point(0x83, 12);
            this.txtNgay_Ct1.Mask = "00/00/0000";
            this.txtNgay_Ct1.Name = "txtNgay_Ct1";
            this.txtNgay_Ct1.OldValue = null;
            this.txtNgay_Ct1.Size = new Size(100, 20);
            this.txtNgay_Ct1.TabIndex = 0;
//            this.txtNgay_Ct1.Value = null;//manager.GetObject("txtNgay_Ct1.Value");
            this.lblNgay_Ct1.AutoSize = true;
            this.lblNgay_Ct1.Font = new Font("Arial", 8.25f);
            this.lblNgay_Ct1.Location = new Point(0x23, 15);
            this.lblNgay_Ct1.Name = "lblNgay_Ct1";
            this.lblNgay_Ct1.Size = new Size(0x2f, 14);
            this.lblNgay_Ct1.TabIndex = 0x66;
            this.lblNgay_Ct1.Text = "Từ ngày";
            this.lblFormat.AutoSize = true;
            this.lblFormat.Font = new Font("Arial", 8.25f);
            this.lblFormat.Location = new Point(0x23, 0x5d);
            this.lblFormat.Name = "lblFormat";
            this.lblFormat.Size = new Size(0x38, 14);
            this.lblFormat.TabIndex = 0x68;
            this.lblFormat.Text = "Định dạng";
            this.txtFormat.CharacterCasing = CharacterCasing.Upper;
            this.txtFormat.CheckTextSearched = false;
            this.txtFormat.DisabledForeColor = Color.Blue;
            this.txtFormat.Font = new Font("Arial", 8.25f);
            this.txtFormat.Location = new Point(0x83, 90);
            this.txtFormat.Name = "txtFormat";
            this.txtFormat.OldValue = null;
            this.txtFormat.Size = new Size(0x9b, 20);
            this.txtFormat.TabIndex = 3;
            this.txtFormat.Text = "000";
            this.txtFormat.Value = "000";
            this.txtStart.Font = new Font("Arial", 8.25f);
            this.txtStart.Location = new Point(0x83, 0x40);
            this.txtStart.Name = "txtStart";
            this.txtStart.NumericPrecision = 20;
            this.txtStart.NumericScaleOnFocus = 0;
            this.txtStart.NumericScaleOnLostFocus = 0;
            int[] bits = new int[4];
            bits[0] = 1;
            this.txtStart.NumericValue = new decimal(bits);
            this.txtStart.OldValue = null;
            this.txtStart.Size = new Size(100, 20);
            this.txtStart.TabIndex = 2;
            this.txtStart.Text = "1";
            this.txtStart.TextAlign = HorizontalAlignment.Right;
            int[] numArray2 = new int[4];
            numArray2[0] = 1;
            this.txtStart.Value = new decimal(numArray2);
            this.lblStart.AutoSize = true;
            this.lblStart.Font = new Font("Arial", 8.25f);
            this.lblStart.Location = new Point(0x23, 0x43);
            this.lblStart.Name = "lblStart";
            this.lblStart.Size = new Size(0x3b, 14);
            this.lblStart.TabIndex = 0x68;
            this.lblStart.Text = "Số bắt đầu";
            this.labelControl2.BorderStyle = BorderStyle.Fixed3D;
            this.labelControl2.Font = new Font("Arial", 8.25f);
            this.labelControl2.Location = new Point(12, 0x7d);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(0x1a0, 2);
            this.labelControl2.TabIndex = 0x68;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.CancelButton = this.btnCancel;
            base.ClientSize = new Size(440, 0xb3);
            base.Controls.Add(this.txtStart);
            base.Controls.Add(this.lblStart);
            base.Controls.Add(this.labelControl2);
            base.Controls.Add(this.lblFormat);
            base.Controls.Add(this.txtFormat);
            base.Controls.Add(this.txtNgay_Ct2);
            base.Controls.Add(this.lblNgay_Ct2);
            base.Controls.Add(this.txtNgay_Ct1);
            base.Controls.Add(this.lblNgay_Ct1);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOk);
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FormResetInvoiceOrder";
            this.Text = "Đ\x00e1nh lại số chứng từ";
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private bool OnOk()
        {
            if ((this.txtNgay_Ct1.Value == SDBNull.Value) || (this.txtNgay_Ct2.Value == SDBNull.Value))
            {
                MessageBox.Show("Chưa nhập đầy đủ ngày đ\x00e1nh lại số chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if ((((DateTime) this.txtNgay_Ct1.Value) <= AppInstance.EndingDateOfSubEnterprice) || (((DateTime) this.txtNgay_Ct2.Value) <= AppInstance.EndingDateOfSubEnterprice))
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtFormat.Text))
            {
                MessageBox.Show("Chưa nhập định dạng số chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (this.txtStart.NumericValue <= 0M)
            {
                MessageBox.Show("Số bắt đầu phải lớn hơn 0!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            AppInstance.StartWorkingDate = (DateTime) this.txtNgay_Ct1.Value;
            AppInstance.EndWorkingDate = (DateTime) this.txtNgay_Ct2.Value;
            this.CheckAccepted = true;
            return true;
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((keyData == (Keys.Control | Keys.Return)) && this.OnOk())
            {
                base.Close();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        public bool CheckAccepted
        {
            get
            {
                return this.ib_CheckAccepted;
            }
            set
            {
                this.ib_CheckAccepted = value;
            }
        }

        public object EndDate
        {
            get
            {
                return this.txtNgay_Ct2.Value;
            }
        }

        public object NumberFormat
        {
            get
            {
                return this.txtFormat.Value;
            }
        }

        public object StartDate
        {
            get
            {
                return this.txtNgay_Ct1.Value;
            }
        }

        public object StartNumber
        {
            get
            {
                return this.txtStart.Value;
            }
        }
    }
}

